$(function() {
    $("#btnSave").click(function(){
        save();
    });
});
$.validator.setDefaults({
    submitHandler : function() {
        save();
    }
});

//录单【保存】按钮
function save() {
    var data = {};
    data.lgs_company_cd =  $("#lgs_company_cd").val(); //物流公司代码
    data.lgs_company_nm = $("[data-id='lgs_company_cd'] .filter-option").text();

    data.goods_name =  $("#goods_name").val(); //货物名称
    data.transport_mode_cd =  $("#transport_mode_cd").val(); //运输方式代码
    data.transport_mode_nm = $("[data-id='transport_mode_cd'] .filter-option").text();
    //data.transport_mode_name = $("#transport_mode_cd").find("option:selected").text();

    data.delivery_qty =  $("#delivery_qty").val(); //发货件数
    data.customer_name =  $("#customer_name").val(); //客户名称
    data.value_statement =  $("#value_statement").val(); //价值声明
    data.consignee =  $("#consignee").val(); //收货人
    data.delivery_method_cd =  $("#delivery_method_cd").val(); //交付方式代码
    data.delivery_method_nm = $("[data-id='delivery_method_cd'] .filter-option").text();

    data.consignee_phone =  $("#consignee_phone").val(); //收货人电话
    data.product_size =  $("#product_size").val(); //产品尺寸
    data.consignee_address =  $("#consignee_address").val(); //收货地址
    data.remark =  $("#remark").val(); //备注

    data.sender =  $("#sender").val(); //发货人
    data.sender_phone =  $("#sender_phone").val(); //发货人电话
    data.sender_address =  $("#sender_address").val(); //发货地址

    data.contract_number =  $("#contract_number").val(); //合同编号

    $.ajax({
        cache : true,
        type : "POST",
        url : "/lgs/orderTemp/mng/add",
        data : JSON.stringify(data),
        dataType: "JSON",
        contentType : 'application/json',
        async : false,//同步请求
        error : function(request) {
            alert("Connection error");
        },
        success : function(data) {
            if (data.code == 0) {
                parent.layer.msg("操作成功");
                parent.reLoad();
                var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                parent.layer.close(index);
            } else {
                parent.layer.msg(data.msg);
            }
        }
    });
}

function validateRule() {
    var icon = "<i class='fa fa-times-circle'></i> ";
    $("#addForm").validate({
        rules : {
            roleName : {
                required : true
            }
        },
        messages : {
            roleName : {
                required : icon + "请输入角色名"
            }
        }
    });
}